package chapter3.No3_1_等待和通知机制.k通过管道进行线程间通信_字节流;

import java.io.*;

/**
 * 线程间通信：字节流
 *    通过管道通信
 *      1. PipedInputStream和PipedOutputStream
 *
 * 备注：先执行了读取操作，当时没有数据写入，所以线程阻塞在 int readLength = pis.read(byteArray)
 *      代码中，直到有数据被写入，才继续向下运行
 * Created by Administrator on 2016/11/19.
 */
public class Main {
    public static void main(String[] args) throws IOException, InterruptedException {
        ReadData readData = new ReadData();
        WriteDate writeDate = new WriteDate();
        PipedInputStream pis = new PipedInputStream();
        PipedOutputStream pos = new PipedOutputStream();

//        pos.connect(pis);
        pis.connect(pos);

        ThreadRead threadRead = new ThreadRead(readData, pis);
        ThreadWrite threadWrite = new ThreadWrite(writeDate, pos);
        threadRead.start();

        Thread.sleep(2000);
        threadWrite.start();

//        byte[] bytes = new byte[20];
//        bytes[0] = 65;
//        System.out.println(new String(bytes));
    }
}
